package com.hzlj.position.locate.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.fz.common.dict.annotation.DictConvert;
import com.hzlj.position.locate.common.dto.abnNightActivityJzry.AbnNightActivityJzryAddDTO;
import com.hzlj.position.locate.common.dto.abnNightActivityJzry.AbnNightActivityJzryQueryResultDTO;
import com.hzlj.position.locate.common.model.AbnNightActivityJzry;
import com.hzlj.position.locate.dao.AbnNightActivityJzryDao;
import com.hzlj.position.locate.service.AbnNightActivityJzryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import static com.hzlj.position.config.config.IdConfig.POSITION_ID_GEN;

/**
 * 定位分析-夜间活动表-人员信息(AbnNightActivityJzry)表服务接口
 *
 * @author lifh
 * @date 2023-10-17 17:38:35
 */
@Slf4j
@Service
public class AbnNightActivityJzryServiceImpl implements AbnNightActivityJzryService {
    @Resource
    private AbnNightActivityJzryDao abnNightActivityJzryDao;


    /**
     * 新增数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveAbnNightActivityJzry(String nightActivityId,
                                         List<AbnNightActivityJzryAddDTO> dtos) {
        List<AbnNightActivityJzry> adds = dtos.stream().map(e -> {
            AbnNightActivityJzry add = BeanUtil.copyProperties(e, AbnNightActivityJzry.class);
            add.setId(POSITION_ID_GEN.nextIdStr());
            add.setPositionId(e.getId());
            add.setNightActivityId(nightActivityId);
            add.setCreateTime(new Date());
            return add;
        }).collect(Collectors.toList());
        this.abnNightActivityJzryDao.saveBatch(adds);
    }


    /**
     * 查询列表：不分页
     */
    @Override
    @DictConvert
    public List<AbnNightActivityJzryQueryResultDTO> listAbnNightActivityJzry(String nightActivityId) {
        return this.abnNightActivityJzryDao.listAbnNightActivityJzry(nightActivityId);
    }
}
